var app = getApp();

Page({
  data: {
    code: !1
  },
  add0: function(m) {
    return m < 10 ? '0' + m : m
  },
  format: function(shijianchuo) {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
  },
  onLoad: function(e) {
    console.log(e);
    var o = this;
    o.setData({
      color: wx.getStorageSync("platform").color,
      url: wx.getStorageSync("url")
    }), app.util.request({
      url: "entry/wxapp/OrderCode",
      data: {
        order_id: e.id
      },
      success: function(e) {
        console.log(e), o.setData({
          bath: e.data
        });
      }
    }), app.util.request({
      url: "entry/wxapp/orderdetails",
      data: {
        order_id: e.id
      },
      success: function(e) {
        console.log(e);
        var t = e.data;
        t.arrival_time = t.arrival_time.slice(5, 7) + "月" + t.arrival_time.slice(8, 10) + "日",
          t.departure_time = t.departure_time.slice(5, 7) + "月" + t.departure_time.slice(8, 10) + "日",
          o.setData({
            order_info: t,
            time: o.format(t.time * 1000)
          });
      }
    }), wx.setNavigationBarColor({
      frontColor: '#000000',
          backgroundColor: '#ffffff'
    });
  },
  confirmorder: function(e) {
    var t = app.OpenId,
      o = this.data.order_info;
    app.util.request({
      url: "entry/wxapp/Pay",
      cachetime: "0",
      data: {
        openid: t,
        money: o.total_cost,
        order_id: o.id
      },
      success: function(e) {
        wx.requestPayment({
          timeStamp: e.data.timeStamp,
          nonceStr: e.data.nonceStr,
          package: e.data.package,
          signType: e.data.signType,
          paySign: e.data.paySign,
          success: function(e) {
            console.log("支付成功"), console.log(e), wx.navigateTo({
              url: './book?orderid=' + o.id,
            })
          },
          fail: function(e) {
            console.log("支付失败"), wx.showToast({
              title: "支付失败"
            });
          }
        });
      }
    });
  },
  order_more: function(e) {
    wx.navigateTo({
      url: "../hotel_list/hotel_info?hotel_id=" + this.data.order_info.seller_id
    });
  },
  see_more: function(e) {
    2 == wx.getStorageSync("platform").type ? wx.navigateTo({
      url: "../hotel_list/hotel_list"
    }) : wx.navigateTo({
      url: "../index/index"
    });
  },
  cancel_order: function(e) {
    var t = e.currentTarget.dataset.id,
      o = e.currentTarget.dataset.hb_id;
    1 == e.currentTarget.dataset.classify ? (console.log(o), app.util.request({
      url: "entry/wxapp/CancelOrder",
      data: {
        order_id: t,
        hb_id: o
      },
      success: function(e) {
        console.log(e), wx.showToast({
          title: "订单已取消"
        }), setTimeout(function() {
          wx.navigateBack({
            delta: 1
          });
        }, 1500);
      }
    })) : wx.showModal({
      title: "",
      content: "钟点房不可以取消"
    });
  },
  apply: function(e) {
    var t = e.currentTarget.dataset.id,
      o = e.currentTarget.dataset.type;
    console.log(t), wx.showModal({
      title: "温馨提示",
      content: "是否申请退款？",
      success: function(e) {
        e.confirm ? (console.log("用户点击确定"), 1 == o ? app.util.request({
          url: "entry/wxapp/ApplyOrder",
          data: {
            order_id: t
          },
          success: function(e) {
            console.log(e), wx.showToast({
              title: "申请成功"
            }), setTimeout(function() {
              wx.navigateBack({
                delta: 1
              });
            }, 1500);
          }
        }) : 2 == o ? app.util.request({
          url: "entry/wxapp/YeRefund",
          data: {
            order_id: t
          },
          success: function(e) {
            console.log(e), wx.showToast({
              title: "申请成功"
            }), setTimeout(function() {
              wx.navigateBack({
                delta: 1
              });
            }, 1500);
          }
        }) : 3 == o && wx.showModal({
          title: "",
          content: "到店付不支持退款"
        })) : e.cancel && console.log("用户点击取消");
      }
    });
  },
  code: function(e) {
    var t = this,
      o = t.data.code;
    1 == o ? t.setData({
      code: !1
    }) : t.setData({
      code: !0
    });
  },
  sele_address: function(e) {
    var a = this.data.order_info,
      n = a.coordinates.split(",");
    wx.getLocation({
      type: "gcj02",
      success: function(e) {
        var t = Number(n[0]),
          o = Number(n[1]);
        wx.openLocation({
          latitude: t,
          longitude: o,
          name: a.seller_name,
          address: a.seller_address
        });
      }
    });
  },
  go_eveluate: function(e) {
    console.log(this.data.order_info.order_no);
    wx.navigateTo({
      url: "evaluate?seller_id=" + this.data.order_info.seller_id + "&order_id=" + this.data.order_info.id + '&order_sn=' + this.data.order_info.order_no
    });
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {}
});